package com.jz.banner.screen.widget.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.widget.TextView
import butterknife.ButterKnife
import com.jz.banner.screen.R
import com.jz.banner.screen.ui.App

class LoadingDialog(context: Context?) : Dialog(context!!, R.style.MyDialog) {
    private var titleTv: TextView? = null
    var mTitle: String? = null
        set(value) {
            field = value
            titleTv?.text = field

        }
    //constructor(context: Context?) : this(context, App.context!!.getString(R.string.loading_now))

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_loading)
        titleTv = findViewById(R.id.loading_title_tv)
        this.setCanceledOnTouchOutside(false)
        setCancelable(false)
        setAttributes()
        ButterKnife.bind(this)
    }

    /**
     * 设置对话框窗口属性
     */
    private fun setAttributes() {
        val dialogWindow = window
        val lp = dialogWindow!!.attributes
        lp.width = App.screenWidth
        lp.height = App.screenHeight
        dialogWindow.attributes = lp
        //TODO:设置不可取消。
        dialogWindow.setGravity(Gravity.CENTER)
    }

    override fun onBackPressed() {
        super.onBackPressed()
    }

    fun setTitleTv(title: String) {
        titleTv?.text = title
    }

}
